﻿<?php    
require 'common.inc.php';
if(empty($o))
{
	$o = 'List';
}   

$id = empty($id) ? 0 : intval($id); //父级值
$field = empty($field) ? 'hidden_area' : $field; //隐藏文本值
$fun = empty($fun) ? 'area_load' :$fun;  //函数名称
$n = empty($n) ? 'area':$n; //表名
$t = empty($t) ? 'name':$t; //字段名
$v = empty($v) ? 'id':$v;  //字段名
$tageid = empty($tageid) ? '' : $tageid; //标签定义id值 
$options ='';
 
if($o=='List')
{   
    $query="select * from {$DT_PRE}".$n." where parentid=".$id;  
	$result =$db->query($query);
	while($frow = $db->fetch_array($result)) { 
		 $options .="<option value=\"".$frow[$v]."\">".$frow[$t]."</option>\r\n";
	  }
	  
	if(!empty($options)){
	   $options = "<select onchange=\"this.disabled=true;$('#".$field."').val(this.value);".$fun."(this.value);\"><option value=\"-2\">请选择</option>".$options."</select>";
	 }
	
	echo $options;
	exit; 
} 
else if($o=='json')
{   
    $options="";
    $query="select * from {$DT_PRE}".$n." where parentid=".$id;  
	$result =$db->query($query);
	//$r = $db->fetch_array($result);
	//$com[]=$r;
	//$options= json_encode($com);  
	 
	while($frow = $db->fetch_array($result)) { 
		 //$options .="<option value=\"".$frow[$v]."\">".$frow[$t]."</option>\r\n";
		 $options .=(($options==''?"":",")."{\"".$v."\":\"".$frow[$v]."\",\"".$t."\":\"".$frow[$t]."\"}");
	}
	  
	if(!empty($options)){
	   //$options = "<select onchange=\"this.disabled=true;$('#".$field."').val(this.value);".$fun."(this.value);\"><option value=\"-2\">请选择</option>".$options."</select>";
	   $options = "{\"R\":\"OK\",\"JSON\":[".$options."]}";
	 } 
	
	echo $options;
	exit; 
} 
else if($o == 'Info'){
    $options="";
    if($id >0){
	    $query="select * from {$DT_PRE}".$n." where $v=".$id;
	    $row = $db->get_one($query);
		$parentid = $row['parentid']; 
		if($parentid ==0)
		{ 
		   echo $row[$t];
		   exit;
		}  
	    $strcode = $row['arrparentid'].','.$id;
		$query="select * from {$DT_PRE}".$n." where find_in_set($v,'".$strcode."')"; 
		 //echo $query;
		$result =$db->query($query);
	    while($frow = $db->fetch_array($result))
		{
			$options .= (($options==""?"":"/").$frow[$t]);
		} 
		echo $options;
		exit; 
	} 
}  
?>